See Archiving workspace Runner with scheme Runner. It would have a clue. Maybe your environment would not be the standard one.
To me, the problem was because of the Generated.xcconfig file and it was from the monorepo directory structure. The flutter project that I wanted to build was in the repository subfolder.
So I added cd to/the/flutter/directory before flutter precache --ios.
And I had used melos, so I called melos bs before that.
The normal melos command doesn't work, so you have to use a global one like:
flutter pub global activate melos
flutter pub global run melos bs
I hope it will help you.